<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
    //     var age =20 
    //     var name = "Tom"
    //     console.log(age)
    //     console.log(name)
    //     var person = new Object();
    //     person.name = "John";
    //     person.age = 30;
    //  person.eat=function(food){
    //     console.log(this.age+"岁"+this.name+"正在吃"+food)
    //  }

    //  console.log(person.name)
    //  console.log(person.age)
    //  person.eat("羊肉火锅")

    // var person = {
    //     name:"张三",
    //     age:10,
    //     eat:function(food){
    //         console.log(this.name+"吃"+food)
    //     }
    // }

     console.log(person.name)
     console.log(person.age)
     person.eat("苹果")
    var person = {
        name:"张三",
        age:"13",
        foods:["苹果","香蕉","西瓜"],
        eat:function(){
            console.log(this.age+"岁的"+this.name+"喜欢吃:")
        for(var i =0;i<this.foods.length;i++)
        {
            console.log(this.foods[i])
        }
        },
    }

    // }
    // console.log(person.name)
    // console.log(person.age)
    // person.eat()
    //遍历对象

    </script>
</head>
<body>
    <p id="demo"></p>
    <script>
            var  x;
            var person = {
        name:"张三",
        age:"13",
        foods:["苹果","香蕉","西瓜"],}
for (x in person) {
  document.getElementById("demo").innerHTML += x + "<br>";
}

    </script>    
</body>
</html>